﻿using UnityEngine;
using System.Collections;

[RequireComponent(typeof(Renderer))]

public class ImageTextLocalize : MonoBehaviour
{
    static string path = "ImageText"; 

    void Awake()
    {
        ChangeTexture();
    }


    void ChangeTexture()
    {
        string materialName = renderer.material.name.Replace(" (Instance)", "");
        materialName = materialName.Remove(0, 2);
        Debug.Log(materialName);

        if(Localization.language == Language.text_EN.ToString())    // 영문
        {
            ChangeMaterial(string.Format("{0}/EN/En{1}", path, materialName));
        }
        else if(Localization.language == Language.text_CN.ToString())  // 중문
        {
            ChangeMaterial(string.Format("{0}/CN/Cn{1}", path, materialName));
        }
        else if (Localization.language == Language.text_DE.ToString())  // 중문
        {
            ChangeMaterial(string.Format("{0}/DE/De{1}", path, materialName));
        }
        else if (Localization.language == Language.text_RU.ToString())  // 중문
        {
            ChangeMaterial(string.Format("{0}/RU/Ru{1}", path, materialName));
        }
    }

    void ChangeMaterial(string prefapPath)
    {
        Debug.Log(prefapPath);

        Material prefab = ResourceLoader.Load(prefapPath, typeof(Material)) as Material;

        renderer.material = prefab;
    }

    void OnLanguageChange()
    {
        ChangeTexture();
    }
}
